const mult = (...args) => {
    return args.reduce((x, y) => x * y);
}

const plus = (...args) => {
    return args.reduce((x, y) => x + y);
}

// 缓存代理
const createProxyFactory = (fn) => {
    let cache = {}; // 缓存输出结果
    return (...args) => {
        let key = args.join(',');
        if (key in cache) return cache[key];
        return cache[key] = fn(...args);
    }
}

let proxyMult = createProxyFactory( mult );
let proxyPlus = createProxyFactory( plus );

console.log( proxyMult(1, 2, 3, 4) );
console.log( proxyMult(1, 2, 3, 4) );
console.log( proxyPlus(1, 2, 3, 4) );
console.log( proxyPlus(1, 2, 3, 4) );
